<?php
namespace app\admin\controller;
use think\Controller;
use think\Db;

class Videotype extends BaseController
{
    public function index(){
	$t=Db::name('videotype')->select();
	$this->assign('videotype',$t);
	return $this->fetch();
	}
	public function delete($id){
		if(db("videotype")->delete($id)){
			$this->success("删除成功");
		}else{
			$this->error("删除失败");
		}
	}
	public function add(){
	$tp=$_POST["typename"];
	$typename=input('param.typename');
	$num=Db::name("videotype")->where("typename='$typename'")->count();
	if($num>0)
		$this->error("该类型已经存在");
	$data=["typename"=>$typename];
	if(Db::name("videotype")->insert($data)){
		$this->success("添加类型成功");
	}else $this->error("添加类型失败");
		}


	public function edit(){
		$tid=input("param.tid");
		$type=Db::name("Videotype")->find($tid);
		echo json_encode($type);
	}
	
	public function update(){
		$typename=input('param.typename');
		$num=Db::name("videotype")->where("typename='$typename'")->count();
		if($num>0)
			$this->error("该类型已经存在");
		$data=[
		"tid"=>input("param.tid"),
		"typename"=>input("param.typename"),];
		if(Db::name("videotype")->update($data)){
			$this->success("修改类型成功");
		}else{
			$this->error("修改类型失败");
		}

	}
}
